//
//  LMRecordTableViewCell.swift
//  WeiBo
//
//  Created by Li MAc on 2018/11/28.
//  Copyright © 2018 Li MAc. All rights reserved.
//

import UIKit

class LMRecordTableViewCell: UITableViewCell {

    @IBOutlet weak var icon: UIImageView!
    
    @IBOutlet weak var name: UILabel!
    
    @IBOutlet weak var dengji: UIImageView!
    
    @IBOutlet weak var time: UILabel!
    
    @IBOutlet weak var home: UILabel!
    
    @IBOutlet weak var vnumbe: UIImageView!
    
    @IBOutlet weak var zwtext: UILabel!
    
    @IBOutlet weak var toolBar: LMToolBar!
    
    @IBOutlet weak var peituView: LMPeituView!
    
    
    //此处应该改成可选值，当是原创时是没有值的
    @IBOutlet weak var bztext: UILabel?
    
    
    
    private lazy var statusModel = LMStatusViewMode()
    
    
    //cell 数据设置
    var recordviewModel : WBStatusViewModel?{
        didSet{
        name.text = recordviewModel?.status.user?.screen_name

        zwtext?.text = recordviewModel?.status.text
        
        name.text = recordviewModel?.status.user?.screen_name
        //微博等级图标
        let img = recordviewModel?.status.user?.mbrank ?? 1
        if img>0 && img<7 {
            let imgname = "common_icon_membership_level\(img)"
            dengji.image = UIImage(named: imgname)
        }


        //认证图标

        let ren = recordviewModel?.status.user?.verified_type ?? -1
        switch ren {
        case 0:
            vnumbe.image = UIImage(named: "avatar_vip")
        case 2,3,5:
            vnumbe.image = UIImage(named: "avatar_enterprise_vip")
        case 220:
            vnumbe.image = UIImage(named: "avatar_grassroot")
        default:
            break
        }
        let urlstring = recordviewModel?.status.user?.profile_image_url
        let url = URL(string: urlstring!)

        icon.setImageWith(url!, placeholderImage: UIImage(named: "avatar_default"))
        //设置圆形头像
        icon.layer.masksToBounds = true
        icon.layer.cornerRadius = 17
            
            
            
            //底部工具栏
            toolBar.ToolBarModel = recordviewModel
            
            //设置配图视图
            peituView.peitue = recordviewModel
            
            //设置配图视图的高度
            peituView.ImgHeight.constant = recordviewModel?.pictureViewSize.height ?? 0
//            peitue?.status.pic_urls?.count
            if recordviewModel?.status.pic_urls?.count == 0 {
                peituView.peiandtoolbarHeight.constant = 0
            }else {
                peituView.peiandtoolbarHeight.constant = 12
            }
            
            //设置配图
            peituView.imgurls = recordviewModel?.picURL
            
            
            //设置被转发的文字
            recordviewModel?.bzStatustext = "@" + (recordviewModel?.status.user?.screen_name ?? "") + (recordviewModel?.status.text ?? "")
            
            bztext?.text = recordviewModel?.bzStatustext
        }
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        //离屏渲染 - 异步绘制
        self.layer.drawsAsynchronously = true
        
        
        self.layer.drawsAsynchronously = true
        //栅格化 ，必须注意指定分辨率
        self.layer.rasterizationScale = UIScreen.main.scale
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
